package com.myblog.mapper;

import com.myblog.model.Article;
import com.myblog.model.ArticleLikes;
import com.myblog.model.CommentLikes;
import com.myblog.model.LeaveLikes;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface LikeMapper {

    @Select("select * from article_likes_record order by id desc ")
    List<ArticleLikes> selectAllArticleLikes();

    @Select("select likerId from article_likes_record order by id desc ")
    List<Integer> selectAllArticleLikesId();

    @Select("select count(id) from article_likes_record where isRead = 1")
    Integer selectMsgIsNotReadNum();

    @Update("update article_likes_record set isRead = 0 where isRead = 1")
    void updateAllArticleLikesIsRead();

    @Select("select count(*) from article_likes_record where articleId =#{articleId}")
    Integer selectNumOfArticleLikeByArticleId(long articleId);

    @Select("select * from article_likes_record where articleId = #{articleId} and likerId = #{likerId}")
    ArticleLikes isLike(@Param(value = "articleId") long articleId, @Param(value = "likerId")Integer likerId);

    void insertArticleLikesRecords(ArticleLikes likeOfArticle);

    @Select("select count(*) from article_likes_record where isRead = 1")
    Integer selectNumOfUnReadLikes();

    @Select("select * from leave_message_likes_record where pageName = #{pageName} " +
            "and pId = #{pId} and likerId = #{likerId}")
    LeaveLikes LeaveIsLike(@Param(value = "pageName")String pageName, @Param(value = "pId")Integer leaveId, @Param(value = "likerId") Integer id);

    void insertLeaveLikesRecords(LeaveLikes likeOfLeave);

    @Select("select * from comment_likes_record where articleId = #{articleId} " +
            "and pId = #{pId} and likerId = #{likerId}")
    CommentLikes commentIsLike(@Param(value = "articleId")long articleId, @Param(value = "pId")Integer commentId, @Param(value = "likerId")Integer id);

    void insertCommentLikesRecords(CommentLikes likeOfComment);
}
